package cc.lj.internal.payment.infrastructure.repository.mysql;

import cc.lj.internal.core.exception.ServiceException;
import cc.lj.internal.core.model.BasePageHelper;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.payment.domain.settlement.repository.ICouponsSubsidyDetailRepository;
import cc.lj.internal.payment.domain.settlement.repository.ICouponsSubsidyRepository;
import cc.lj.internal.payment.infrastructure.dao.ICouponsSubsidyDetailMapper;
import cc.lj.internal.payment.infrastructure.dao.ICouponsSubsidyMapper;
import cc.lj.internal.payment.infrastructure.exception.PaymentExceptionEnum;
import cc.lj.internal.payment.infrastructure.po.CouponsSubsidyDetailPO;
import cc.lj.internal.payment.infrastructure.po.CouponsSubsidyPO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

/**
 * 电子券分摊表　mysql仓储实现
 * @author liangxifeng
 * @date 2022-10-24
 */
@Repository("couponsSubsidyMysqlRespository")
public class CouponsSubsidyMysqlRespository implements ICouponsSubsidyRepository,BasePageHelper<CouponsSubsidyPO> {
    @Autowired
    private ICouponsSubsidyMapper mapper;
    @Override
    public List list(CouponsSubsidyPO entityPO) {
        QueryWrapper<CouponsSubsidyPO> wrapper = new QueryWrapper<>(entityPO);
        List<CouponsSubsidyPO> entitys = mapper.selectList(wrapper);
        return entitys;
    }

    @Override
    public Integer updateById(CouponsSubsidyPO entityPO) {
        Integer res = mapper.updateById(entityPO);
        if (res != 1)
        {
            throw new ServiceException(PaymentExceptionEnum.UPDATE_COUPONS_SUBSIDY_FAILED);
        }
        return res;
    }

    @Override
    public PageInfo<CouponsSubsidyPO> selectPage(PageParam pageParam) {
        return this.page(pageParam);
    }


    @Override
    public List<CouponsSubsidyPO> getList(CouponsSubsidyPO subsidyPO) {
        return this.list(subsidyPO);
    }

    @Override
    public Integer insert(CouponsSubsidyPO subsidyPO) {
        Integer rows = mapper.insert(subsidyPO);
        if(rows != 1) {
            throw new ServiceException(PaymentExceptionEnum.INSERT_COUPONS_SUBSIDY_FAILED);
        }
        return subsidyPO.getId();
    }

    @Override
    public CouponsSubsidyPO getById(Integer id) {
        return mapper.selectById(id);
    }

}
